package model

import (
	"encoding/json"

	"openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/common/enum/script"
	"openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/common/enum/workflow"
)

type TaskWorkflow struct {
	ID            int                    `json:"id" gorm:"primaryKey;autoIncrement;comment:作业编排Id"`
	Name          string                 `json:"name" gorm:"comment:作业编排名称"`
	Description   string                 `json:"description" gorm:"comment:作业描述"`
	Tag           string                 `json:"tag" gorm:"comment:场景标签"`
	PublishStatus workflow.PublishStatus `json:"publish_status" gorm:"comment:发布状态"`
	OperationType string                 `json:"operation_type" gorm:"comment:操作类型"`
	UsageType     workflow.UsageType     `json:"usage_type" gorm:"comment:编排业务类型"`
	FirstStepNum  int                    `json:"first_step_num"`
	LastStepNum   int                    `json:"last_step_num"`
	ToSync        bool                   `json:"to_sync" gorm:"type:tinyint(1);default:0;comment:是否需要更新引用脚本"`
	ModifyUser    string                 `json:"modify_user" gorm:"not null;comment:'最后修改者'"`
	ModifyTime    string                 `json:"modify_time" gorm:"comment:'最后修改时间'"`
}

type TaskWorkflowParams struct {
	ID          int             `json:"id" gorm:"primaryKey;autoIncrement"`
	WorkflowId  int             `json:"workflow_id" gorm:"comment:作业编排Id"`
	Name        string          `json:"name" gorm:"comment:输入参数名称"`
	Type        string          `json:"type" gorm:"comment:参数类型(string、number、host、json等)"`
	DefaultVaue json.RawMessage `json:"default_value" gorm:"comment:参数默认值"`
	Description string          `json:"description" gorm:"comment:输入参数描述"`
	IsRequired  bool            `json:"is_required" gorm:"comment:是否必需"`
}

type TaskWorkflowOutputParams struct {
	ID          int    `json:"id" gorm:"primaryKey;autoIncrement"`
	WorkflowId  int    `json:"workflow_id" gorm:"comment:作业编排Id"`
	Name        string `json:"name" gorm:"comment:输出参数名称"`
	Type        string `json:"type" gorm:"comment:参数类型"`
	Description string `json:"description" gorm:"comment:输出参数描述"`
}

type TaskWorkflowStep struct {
	ID              int               `json:"id" gorm:"primaryKey;autoIncrement"`
	WorkflowId      int               `json:"workflow_id" gorm:"comment:作业编排Id"`
	StepType        workflow.StepType `json:"step_type" gorm:"comment:编排步骤类型"`
	Name            string            `json:"name"  gorm:"comment:步骤名称"`
	StepNum         int               `json:"step_num" gorm:"comment:作业编排步骤Id"`
	PreviousStepNum int               `json:"previous_step_num" gorm:"comment:作业编排上一步骤Id"`
	NextStepNum     int               `json:"next_step_num" gorm:"comment:作业编排下一步骤Id"`
}

type TaskWorkflowStepScript struct {
	ID                     int               `json:"id" gorm:"primaryKey;autoIncrement"`
	WorkflowId             int               `json:"workflow_id" gorm:"comment:作业编排Id"`
	StepNum                int               `json:"step_num" gorm:"comment:作业编排步骤Id"`
	ScriptType             script.ScriptType `json:"script_type"  gorm:"comment:脚本类型"`
	ScriptId               string            `json:"script_id"  gorm:"comment:引用脚本Id"`
	ToSync                 bool              `json:"to_sync" gorm:"type:tinyint(1);default:0;comment:是否需要更新引用脚本"`
	ScriptVersionId        int               `json:"script_version_id"  gorm:"comment:引用脚本版本Id"`
	ScriptPublishedVersion string            `json:"script_published_version"  gorm:"comment:引用脚本发布版本"`
	ScriptContent          string            `json:"script_content"  gorm:"comment:脚本内容"`
	ScriptParam            string            `json:"script_param"  gorm:"comment:脚本执行参数"`
	ScriptTimeout          int               `json:"script_timeout"  gorm:"comment:脚本超时"`
}

type TaskWorkflowDTO struct {
	Workflow     TaskWorkflow               `json:"workflow"`
	Params       []TaskWorkflowParams       `json:"params"`
	OutputParams []TaskWorkflowOutputParams `json:"output_params"`
	Steps        []TaskWorkflowStep         `json:"steps"`
	Scripts      []TaskWorkflowStepScript   `json:"scripts"`
}

type WorkflowStepDetail struct {
	StepNum  int               `json:"step_num"`
	StepType workflow.StepType `json:"step_type"`

	ScriptType      int    `json:"script_type"`
	ScriptId        string `json:"script_id"`
	ScriptVersionId int    `json:"script_version_id"`
	ScriptContent   string `json:"script_content"`
	ScriptParam     string `json:"script_param"`
	ScriptTimeout   int    `json:"script_timeout"`
}
